package com.atguigu4.search_sort.exer2;

/**
 * @author NoobMaster69  * @date 2024/5/27 0027 星期一 16:09
 */
public class DoubleSearch {
    public static void main(String[] args) {

       int[] arr2 = new int[]{2,4,5,8,12,15,19,26,37,49,51,66,89,100};
       int head = 0;
       int end = arr2.length - 1;
       int target = 5;

       boolean flag = true;
       while (head <= end){
           int mid = (head + end ) /2;
           if(target == arr2[mid]){
               System.out.println("找到了" + target + "位置是:" + mid );
               flag = false;
               break;
           }else if(target > arr2[mid]){
               head = mid + 1;
           }else if(target < arr2[mid]){
               end = mid - 1;
           }
       }

       if(flag){
           System.out.println("没捞着");
       }

    }
}
